/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import DTO.DoanhThuKH_DTO;
import DTO.DoanhThuNV_DTO;
import DTO.DoanhThuNgay_DTO;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Phung
 */
public class DoanhThuBanVe_DAO {
    
    public static ArrayList<DoanhThuNgay_DTO> Get_DoanhThuNgayChon(Date TuNgay, Date DenNgay) throws SQLException{
        ArrayList<DoanhThuNgay_DTO> ds = new ArrayList<>();
        MySQLDataHelper_DAO.open();
        Connection Con = MySQLDataHelper_DAO.getConnection();
        CallableStatement statement = Con.prepareCall("{call DoanhThuTheoNgayChon(?,?)}");
        statement.setDate(1, TuNgay);
        statement.setDate(2, DenNgay);
        statement.execute();
        ResultSet Rs = statement.getResultSet();
        if(Rs.next()){
            DoanhThuNgay_DTO DoanhThu = new DoanhThuNgay_DTO();
            DoanhThu.setNgayBan(Rs.getDate("CT_GD.NgayGD"));
            DoanhThu.setDanhSoBanVe(Rs.getDouble("SUM(CT_GD.ThanhTien)"));
            ds.add(DoanhThu);
        }
        return ds;
    }
     public static ArrayList<DoanhThuNgay_DTO> Get_DoanhThuNgay() throws SQLException{
        ArrayList<DoanhThuNgay_DTO> ds = new ArrayList<>();
        MySQLDataHelper_DAO.open();
        Connection Con = MySQLDataHelper_DAO.getConnection();
        CallableStatement statement = Con.prepareCall("{call DoanhThuTheoNgay()}");
        statement.execute();
        ResultSet Rs = statement.getResultSet();
        if(Rs.next()){
            DoanhThuNgay_DTO DoanhThu = new DoanhThuNgay_DTO();
            DoanhThu.setNgayBan(Rs.getDate("CT_GD.NgayGD"));
            DoanhThu.setDanhSoBanVe(Rs.getDouble("SUM(CT_GD.ThanhTien)"));
            ds.add(DoanhThu);
        }
        return ds;
    }
    
    public static ArrayList<DoanhThuKH_DTO> Get_DoanhThuKHChon(Date TuNgay, Date DenNgay) throws SQLException{
        ArrayList<DoanhThuKH_DTO> ds = new ArrayList<>();
        MySQLDataHelper_DAO.open();
        Connection Con = MySQLDataHelper_DAO.getConnection();
        CallableStatement statement = Con.prepareCall("{call DoanhThuKhachHangTheoNgay(?,?)}");
        statement.setDate(1, TuNgay);
        statement.setDate(2, DenNgay);
        statement.execute();
        ResultSet Rs = statement.getResultSet();
        if(Rs.next()){
            DoanhThuKH_DTO DoanhThu = new DoanhThuKH_DTO();
            DoanhThu.setMaKH(Rs.getString("GD.MaKH"));
            DoanhThu.setTenKH(Rs.getString("Kh.HoTen"));
            DoanhThu.setTongTien(Rs.getDouble("SUM(CT_GD.ThanhTien)"));
            ds.add(DoanhThu);
        }
        return ds;
    }
    
    public static ArrayList<DoanhThuKH_DTO> Get_DoanhThuKH() throws SQLException{
        ArrayList<DoanhThuKH_DTO> ds = new ArrayList<>();
        MySQLDataHelper_DAO.open();
        Connection Con = MySQLDataHelper_DAO.getConnection();
        CallableStatement statement = Con.prepareCall("{call DoanhThuKhachHang()}");
        statement.execute();
        ResultSet Rs = statement.getResultSet();
        if(Rs.next()){
            DoanhThuKH_DTO DoanhThu = new DoanhThuKH_DTO();
            DoanhThu.setMaKH(Rs.getString("GD.MaKH"));
            DoanhThu.setTenKH(Rs.getString("Kh.HoTen"));
            DoanhThu.setTongTien(Rs.getDouble("SUM(CT_GD.ThanhTien)"));
            ds.add(DoanhThu);
        }
        return ds;
    }
    
    public static ArrayList<DoanhThuNV_DTO> Get_DoanhThuNVChon(Date TuNgay, Date DenNgay) throws SQLException{
        ArrayList<DoanhThuNV_DTO> ds = new ArrayList<>();
        MySQLDataHelper_DAO.open();
        Connection Con = MySQLDataHelper_DAO.getConnection();
        CallableStatement statement = Con.prepareCall("{call DoanhThuNhanVienTheoNgay(?,?)}");
        statement.setDate(1, TuNgay);
        statement.setDate(2, DenNgay);
        statement.execute();
        ResultSet Rs = statement.getResultSet();
        if(Rs.next()){
            DoanhThuNV_DTO DoanhThu = new DoanhThuNV_DTO();
            DoanhThu.setMaNV(Rs.getString("Nv.MaNV"));
            DoanhThu.setTenNV(Rs.getString("Nv.TenNV"));
            DoanhThu.setDiaChi(Rs.getString("Nv.DiaChi"));
            DoanhThu.setDienThoai(Rs.getString("Nv.DienThoai"));
            DoanhThu.setTongTien(Rs.getDouble("SUM(CT_GD.ThanhTien)"));
            ds.add(DoanhThu);
        }
        return ds;
    }
    
    public static ArrayList<DoanhThuNV_DTO> Get_DoanhThuNV() throws SQLException{
        ArrayList<DoanhThuNV_DTO> ds = new ArrayList<>();
        MySQLDataHelper_DAO.open();
        Connection Con = MySQLDataHelper_DAO.getConnection();
        CallableStatement statement = Con.prepareCall("{call DoanhThuNhanVien()}");
        statement.execute();
        ResultSet Rs = statement.getResultSet();
        if(Rs.next()){
            DoanhThuNV_DTO DoanhThu = new DoanhThuNV_DTO();
            DoanhThu.setMaNV(Rs.getString("Nv.MaNV"));
            DoanhThu.setTenNV(Rs.getString("Nv.TenNV"));
            DoanhThu.setDiaChi(Rs.getString("Nv.DiaChi"));
            DoanhThu.setDienThoai(Rs.getString("Nv.DienThoai"));
            DoanhThu.setTongTien(Rs.getDouble("SUM(CT_GD.ThanhTien)"));
            ds.add(DoanhThu);
        }
        return ds;
    }
}
